using UnityEngine;
using System.Collections;

/// \class  gkSpawningAngularVelocityModifier
/// \brief  Select an angular velocity
[AddComponentMenu("GK/Engine/Game/Spawn/gkSpawningAngularVelocityModifier")]
public class gkSpawningAngularVelocityModifier : gkSpawningModifier
{
	/// The minimum speed
	public float SpeedMin;
	/// The maximum speed
	public float SpeedMax;
	
	/// \brief  Event called at the and of the actor spawn
	public override void ModifySpawnedActor(GameObject a_rSpawnedActor, int a_iNumActorsInCurrentBatch, int a_iNbActorsInCurrentBatch)
	{
		RandomVelocityChange(a_rSpawnedActor);
	}
	
	/// \brief  Random velocity change
	void RandomVelocityChange(GameObject a_rSpawnedActor)
	{
		float fRandomSpeed;
		Quaternion oRandomRotation;
			
		// Select the random speed
		fRandomSpeed = Random.Range(SpeedMin, SpeedMax);
	
		// Select the random direction
		oRandomRotation = Random.rotation;
	
		// Set the angular velocity
		a_rSpawnedActor.GetComponent<gkPhysicComponent>().SetAngularVelocity(oRandomRotation.eulerAngles * fRandomSpeed);
	}
}